//
//  ViewController.m
//  BOCNetworkImage
//
//  Created by LeungChaos on 16/5/19.
//  Copyright © 2016年 liang. All rights reserved.
//

#import "ViewController.h"
#import "BOCNetworkImage.h"
#import "BOCActivityView.h"

#import "SDWebImage/SDImageCache.h"

#import "InfinityScrollView.h"

@interface ViewController ()

@property (nonatomic, strong) NSArray *imagePathArray;

@end

@implementation ViewController



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
//        NSLog(@"%@",NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES).lastObject);
    
//
//    UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
//    
//    [self.view addSubview:btn];
//    
//    [btn setNetworkImageForState:UIControlStateNormal withURL:[NSURL URLWithString:@"http://cdn1626.clouddn.com/public/upload/zixun/2016/03/14/080a18e58135ffbceb75cda45a66f85crpTZAa_320x320.jpg"] completion:^(UIImage *image, NSURLResponse *response, NSError *error) {
//        
//    }];
    
    
//    
//    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
//    [self.view addSubview:imageView];
//    
//    NSURL *url = [NSURL URLWithString:@"http://att.qyer.com/day_120623/120623121086293314b75dbf0c.jpg"];
    
    
    
    
//    [imageView setNetworkImageWithURL:url placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
//    
//    
//    [imageView setNetworkImageWithURL:url placeholderImage:[UIImage imageNamed:@"placeholder.png"] completion:^(UIImage *image, NSURLResponse *response, NSError *error) {
//        NSLog(@"completion");
//    }];
    
//    [imageView setNetworkImageWithURL:url progress:^(NSProgress * _Nonnull progress) {
//        NSLog(@"progress:%.2f%%",(1.0 * progress.completedUnitCount/progress.totalUnitCount) *100);
//    } completion:^(UIImage *image, NSURLResponse *response, NSError *error) {
//        NSLog(@"completion");
//    }];
    
    
    
//    // 清除过期的缓存
//    [[BOCNetworkImageManager sharedManager] cleanExpiredFileCompletion:^{
//        
//    }];
//    
    // 清除框架中所有缓存
    [[BOCNetworkImageManager sharedManager] clearAllImageCacheWithState:^(BOOL isSeccess) {
        NSLog(@"%@",isSeccess?@"Seccess":@"Fail");
    }];
    
//    [[SDImageCache sharedImageCache]clearDisk];
    
    
//    [[BOCNetworkImageManager sharedManager] imageCacheFileSizeBlock:^(long long size) {
//        NSLog(@"%.2lfMB",1.0 *size / 1024 / 1024);
//    }];
    
    
    InfinityScrollView *is = [[InfinityScrollView alloc]initWithImageNames:self.imagePathArray isNetwork:YES indexDidChangeBlock:nil];
    
    [is setFrame:[[UIScreen mainScreen] bounds]];
    
    [self.view addSubview:is];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}




#pragma mark - lazy load

- (NSArray *)imagePathArray
{
    if (_imagePathArray == nil) {
//        _imagePathArray = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"images" ofType:@"plist"]];
        
        _imagePathArray = @[@"http://www.ysxw.cn/uploads/allimg/140303/22-140303113J2111.jpg",
                            @"http://img1.imgtn.bdimg.com/it/u=140217999,2416768390&fm=21&gp=0.jpg",
                            @"http://img.bimg.126.net/photo/R-fjU_246Fu8y5oy0kmgdg==/5784592246381123707.jpg",
                            @"http://dl.bizhi.sogou.com/images/2012/02/20/143097.jpg",
                            @"http://file21.mafengwo.net/M00/0E/59/wKgB21AGqaKaOYnMABFdhklhi_M81.jpeg",
                            @"http://youimg1.c-ctrip.com/target/fd/tg/g3/M05/4F/79/CggYGVZZQeCAFcpBAA5zurHSSnI304.jpg",
                            @"http://cdn.duitang.com/uploads/item/201509/26/20150926184952_cFUGk.jpeg",
                            @"http://dl.bizhi.sogou.com/images/2012/04/09/127987.jpg?f=download",
                            @"http://att.qyer.com/day_120623/120623121086293314b75dbf0c.jpg",
                            @"http://news.mydrivers.com/img/20140621/0ec4b17876624ab89e27bddb3f421f6f.jpg",
                            @"http://www.uhenan.com/travel/uploads/shaolin/20081017163325493.jpg",
                            @"http://img5.imgtn.bdimg.com/it/u=2306083207,1473928984&fm=21&gp=0.jpg",
                            @"http://www.jydoc.com/uploads/jydoc/p23501/20092322374759377806.jpg",
                            @"http://www.cnuhd.com/data/attachment/forum/201405/23/182905pzhm6nvhyabtqra6.jpg",
                            @"http://file21.mafengwo.net/M00/8A/A1/wKgB3FD0pR2ATc_WAAqHhRAwv3E87.jpeg",
                            @"http://www.deskcar.com/desktop/fengjing/20071213141023/9.jpg",
                            @"http://www.hbyjgs.net/uploads/132.jpg",
                            @"http://www.1986ly.com/files/2013-10/20131025100623121592.jpg",
                            @"http://dimg02.c-ctrip.com/images/fd/tg/g2/M0A/BC/6C/CghzgVUPj3iAVWeSAA9eW-Lv13I138.jpg",
                            @"http://img1.imgtn.bdimg.com/it/u=1813296622,1429553595&fm=21&gp=0.jpg",
                            @"http://att.bbs.duowan.com/forum/201403/03/183406wcjm1xo7tb7lxwcl.jpg",
                            @"http://youimg1.c-ctrip.com/target/fd/tg/g2/M01/8A/95/CghzgFWw0EiAek_yACKz-aC-8hM947.jpg"];
    }
    return _imagePathArray;
}

@end






